package com.csthink.web.infrastructure.security.authentication.provider;

import com.csthink.web.infrastructure.security.authentication.domain.JwtAuthenticationToken;
import com.csthink.web.infrastructure.security.authentication.parser.AbstractAuthenticationParser;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;

/**
 * As we already parse and verify jwt token in the {@link AbstractAuthenticationParser }.<br>
 * So in this provider, we just return the Authentication object.
 *
 * @author <a href="mailto:security.2009@live.cn">Mars</a>
 * @since 2023-09-12
 */
public class JwtAuthenticationProvider implements AuthenticationProvider {

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        return authentication;
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return authentication.isAssignableFrom(JwtAuthenticationToken.class);
    }

}
